﻿using System;
using Cqrs.Infrastructure;
using Cqrs.Infrastructure.Aggregate;

namespace Harmonic.Domain
{
    public class User : AggregateRootWithState
    {
        private string _username;
        private string _email;
        private string _password;
        private DateTime _dateDeleted;

        public User() { }

        private void Apply(UserCreated userCreated)
        {
            Id = userCreated.Id;
            _username = userCreated.Username;
            _email = userCreated.Email;
            _password = userCreated.Password;
        }

        private void Apply(UserMadePriority userMadePriority)
        {
        }

        private void Apply(UserDeleted userDeleted)
        {
            _dateDeleted = userDeleted.DateDeleted;
        }

        private void Apply(UserMadeActive userMadeActive)
        {
        }

        // Public Domain Methods
        public User(string username, string email, string password)
        {
            this.ApplyChange(new UserCreated(Guid.NewGuid(), username, email, password));
        }

        public void DowngradeUser(string reason)
        {
            this.ApplyChange(new UserMadeActive(Id, reason));
        }

        public void UpgradeUser(string reason)
        {
            this.ApplyChange(new UserMadePriority(Id, reason));
        }

        public void DeleteUser(string reason, DateTime dateDeleted)
        {
            this.ApplyChange(new UserDeleted(Id, reason, dateDeleted));
        }
    }
}
